package com.cloud.tsp.controller;

import com.cloud.api.constants.StrVo;
import com.cloud.api.domain.alarm.AlarmReason;
import com.cloud.core.util.R;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.tsp.service.IAlarmReasonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2024-02-21
 */
@RestController
@RequestMapping("/alarm-reason")
public class AlarmReasonController {

    @Resource
    private IAlarmReasonService alarmReasonService;

    @Tag(name = "v1.0")
    @Operation(summary = "根据code查询报警原因（管理）")
    @PostMapping("/getAlarmReasonList")
    @Log(title = "报警方案管理-根据code查询报警原因", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<AlarmReason> selectAlarmReasonList(@RequestBody @Valid StrVo para){
        return R.ok(alarmReasonService.selectAlarmReasonList(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "根据id查询报警原因（管理）")
    @PostMapping("/getAlarmReasonListById")
    @Log(title = "报警方案管理-根据id查询报警原因", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<AlarmReason> selectAlarmReasonListById(@RequestBody @Valid StrVo para){
        return R.ok(alarmReasonService.selectAlarmReasonListById(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改报警原因（管理）")
    @PostMapping("/InsertOrUpdate")
    @Log(title = "报警方案管理-新增或修改报警原因", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdate(@RequestBody @Validated AlarmReason para){
        alarmReasonService.InsertOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "删除报警原因（管理）")
    @PostMapping("/deleteById")
    @Log(title = "报警方案管理-删除报警原因", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R deleteById(@RequestBody @Valid StrVo para){
        alarmReasonService.deleteById(para.getId());
        return R.ok();
    }
}